home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 85 / CD Actual 85 Febrero 2004.iso / Experto / Apache / apache_2.0.48-win32-x86-no_ssl.msi / Data.Cab / F251826_util_ldap.h < prev    next >
Encoding:
C/C++ Source or Header  |  2003-03-07  |  14.3 KB  |  319 lines

  1. /* ====================================================================
  2.  * The Apache Software License, Version 1.1
  3.  *
  4.  * Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
  5.  * reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  *
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  *
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in
  16.  *    the documentation and/or other materials provided with the
  17.  *    distribution.
  18.  *
  19.  * 3. The end-user documentation included with the redistribution,
  20.  *    if any, must include the following acknowledgment:
  21.  *       "This product includes software developed by the
  22.  *        Apache Software Foundation (http://www.apache.org/)."
  23.  *    Alternately, this acknowledgment may appear in the software itself,
  24.  *    if and wherever such third-party acknowledgments normally appear.
  25.  *
  26.  * 4. The names "Apache" and "Apache Software Foundation" must
  27.  *    not be used to endorse or promote products derived from this
  28.  *    software without prior written permission. For written
  29.  *    permission, please contact apache@apache.org.
  30.  *
  31.  * 5. Products derived from this software may not be called "Apache",
  32.  *    nor may "Apache" appear in their name, without prior written
  33.  *    permission of the Apache Software Foundation.
  34.  *
  35.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38.  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46.  * SUCH DAMAGE.
  47.  * ====================================================================
  48.  *
  49.  * This software consists of voluntary contributions made by many
  50.  * individuals on behalf of the Apache Software Foundation.  For more
  51.  * information on the Apache Software Foundation, please see
  52.  * <http://www.apache.org/>.
  53.  */
  54.  
  55. #ifndef UTIL_LDAP_H
  56. #define UTIL_LDAP_H
  57.  
  58. #include <apr_ldap.h>
  59.  
  60. /* this whole thing disappears if LDAP is not enabled */
  61. #ifdef APU_HAS_LDAP
  62.  
  63. /* APR header files */
  64. #include <apr_thread_mutex.h>
  65. #include <apr_thread_rwlock.h>
  66. #include <apr_tables.h>
  67. #include <apr_time.h>
  68.  
  69. /* Apache header files */
  70. #include "ap_config.h"
  71. #include "httpd.h"
  72. #include "http_config.h"
  73. #include "http_core.h"
  74. #include "http_log.h"
  75. #include "http_protocol.h"
  76. #include "http_request.h"
  77.  
  78.  
  79. /* Create a set of LDAP_DECLARE(type), LDLDAP_DECLARE(type) and 
  80.  * LDAP_DECLARE_DATA with appropriate export and import tags for the platform
  81.  */
  82. #if !defined(WIN32)
  83. #define LDAP_DECLARE(type)            type
  84. #define LDAP_DECLARE_NONSTD(type)     type
  85. #define LDAP_DECLARE_DATA
  86. #elif defined(LDAP_DECLARE_STATIC)
  87. #define LDAP_DECLARE(type)            type __stdcall
  88. #define LDAP_DECLARE_NONSTD(type)     type
  89. #define LDAP_DECLARE_DATA
  90. #elif defined(LDAP_DECLARE_EXPORT)
  91. #define LDAP_DECLARE(type)            __declspec(dllexport) type __stdcall
  92. #define LDAP_DECLARE_NONSTD(type)     __declspec(dllexport) type
  93. #define LDAP_DECLARE_DATA             __declspec(dllexport)
  94. #else
  95. #define LDAP_DECLARE(type)            __declspec(dllimport) type __stdcall
  96. #define LDAP_DECLARE_NONSTD(type)     __declspec(dllimport) type
  97. #define LDAP_DECLARE_DATA             __declspec(dllimport)
  98. #endif
  99.  
  100.  
  101. /*
  102.  * LDAP Connections
  103.  */
  104.  
  105. /* Values that the deref member can have */
  106. typedef enum {
  107.     never=LDAP_DEREF_NEVER, 
  108.     searching=LDAP_DEREF_SEARCHING, 
  109.     finding=LDAP_DEREF_FINDING, 
  110.     always=LDAP_DEREF_ALWAYS
  111. } deref_options;
  112.  
  113. /* Structure representing an LDAP connection */
  114. typedef struct util_ldap_connection_t {
  115.     LDAP *ldap;
  116.     apr_pool_t *pool;                   /* Pool from which this connection is created */
  117. #if APR_HAS_THREADS
  118.     apr_thread_mutex_t *lock;           /* Lock to indicate this connection is in use */
  119. #endif
  120.     int bound;                          /* Flag to indicate whether this connection is bound yet */
  121.  
  122.     const char *host;                   /* Name of the LDAP server (or space separated list) */
  123.     int port;                           /* Port of the LDAP server */
  124.     deref_options deref;                /* how to handle alias dereferening */
  125.  
  126.     const char *binddn;                 /* DN to bind to server (can be NULL) */
  127.     const char *bindpw;                 /* Password to bind to server (can be NULL) */
  128.  
  129.     int secure;                         /* True if use SSL connection */
  130.  
  131.     const char *reason;                 /* Reason for an error failure */
  132.  
  133.     struct util_ldap_connection_t *next;
  134. } util_ldap_connection_t;
  135.  
  136. /* LDAP cache state information */ 
  137. typedef struct util_ldap_state_t {
  138.     apr_pool_t *pool;           /* pool from which this state is allocated */
  139. #if APR_HAS_THREADS
  140.     apr_thread_mutex_t *mutex;          /* mutex lock for the connection list */
  141. #endif
  142.  
  143.     apr_size_t cache_bytes;     /* Size (in bytes) of shared memory cache */
  144.     long search_cache_ttl;      /* TTL for search cache */
  145.     long search_cache_size;     /* Size (in entries) of search cache */
  146.     long compare_cache_ttl;     /* TTL for compare cache */
  147.     long compare_cache_size;    /* Size (in entries) of compare cache */
  148.  
  149.     struct util_ldap_connection_t *connections;
  150.     char *cert_auth_file; 
  151.     int   cert_file_type;
  152.     int   ssl_support;
  153. } util_ldap_state_t;
  154.  
  155.  
  156. /**
  157.  * Open a connection to an LDAP server
  158.  * @param ldc A structure containing the expanded details of the server
  159.  *            to connect to. The handle to the LDAP connection is returned
  160.  *            as ldc->ldap.
  161.  * @tip This function connects to the LDAP server and binds. It does not
  162.  *      connect if already connected (ldc->ldap != NULL). Does not bind
  163.  *      if already bound.
  164.  * @return If successful LDAP_SUCCESS is returned.
  165.  * @deffunc int util_ldap_connection_open(request_rec *r,
  166.  *                                        util_ldap_connection_t *ldc)
  167.  */
  168. LDAP_DECLARE(int) util_ldap_connection_open(request_rec *r, 
  169.                                             util_ldap_connection_t *ldc);
  170.  
  171. /**
  172.  * Close a connection to an LDAP server
  173.  * @param ldc A structure containing the expanded details of the server
  174.  *            that was connected.
  175.  * @tip This function unbinds from the LDAP server, and clears ldc->ldap.
  176.  *      It is possible to rebind to this server again using the same ldc
  177.  *      structure, using apr_ldap_open_connection().
  178.  * @deffunc util_ldap_close_connection(util_ldap_connection_t *ldc)
  179.  */
  180. LDAP_DECLARE(void) util_ldap_connection_close(util_ldap_connection_t *ldc);
  181.  
  182. /**
  183.  * Destroy a connection to an LDAP server
  184.  * @param ldc A structure containing the expanded details of the server
  185.  *            that was connected.
  186.  * @tip This function is registered with the pool cleanup to close down the
  187.  *      LDAP connections when the server is finished with them.
  188.  * @deffunc apr_status_t util_ldap_connection_destroy(util_ldap_connection_t *ldc)
  189.  */
  190. LDAP_DECLARE_NONSTD(apr_status_t) util_ldap_connection_destroy(void *param);
  191.  
  192. /**
  193.  * Find a connection in a list of connections
  194.  * @param r The request record
  195.  * @param host The hostname to connect to (multiple hosts space separated)
  196.  * @param port The port to connect to
  197.  * @param binddn The DN to bind with
  198.  * @param bindpw The password to bind with
  199.  * @param deref The dereferencing behavior
  200.  * @param secure use SSL on the connection 
  201.  * @tip Once a connection is found and returned, a lock will be acquired to
  202.  *      lock that particular connection, so that another thread does not try and
  203.  *      use this connection while it is busy. Once you are finished with a connection,
  204.  *      apr_ldap_connection_close() must be called to release this connection.
  205.  * @deffunc util_ldap_connection_t *util_ldap_connection_find(request_rec *r, const char *host, int port,
  206.  *                                                           const char *binddn, const char *bindpw, deref_options deref,
  207.  *                                                           int netscapessl, int starttls)
  208.  */
  209. LDAP_DECLARE(util_ldap_connection_t *) util_ldap_connection_find(request_rec *r, const char *host, int port,
  210.                                                   const char *binddn, const char *bindpw, deref_options deref,
  211.                                                   int secure);
  212.  
  213.  
  214. /**
  215.  * Compare two DNs for sameness
  216.  * @param r The request record
  217.  * @param ldc The LDAP connection being used.
  218.  * @param url The URL of the LDAP connection - used for deciding which cache to use.
  219.  * @param dn The first DN to compare.
  220.  * @param reqdn The DN to compare the first DN to.
  221.  * @param compare_dn_on_server Flag to determine whether the DNs should be checked using
  222.  *                             LDAP calls or with a direct string comparision. A direct
  223.  *                             string comparison is faster, but not as accurate - false
  224.  *                             negative comparisons are possible.
  225.  * @tip Two DNs can be equal and still fail a string comparison. Eg "dc=example,dc=com"
  226.  *      and "dc=example, dc=com". Use the compare_dn_on_server unless there are serious
  227.  *      performance issues.
  228.  * @deffunc int util_ldap_cache_comparedn(request_rec *r, util_ldap_connection_t *ldc,
  229.  *                                        const char *url, const char *dn, const char *reqdn,
  230.  *                                        int compare_dn_on_server)
  231.  */
  232. LDAP_DECLARE(int) util_ldap_cache_comparedn(request_rec *r, util_ldap_connection_t *ldc, 
  233.                               const char *url, const char *dn, const char *reqdn, 
  234.                               int compare_dn_on_server);
  235.  
  236. /**
  237.  * A generic LDAP compare function
  238.  * @param r The request record
  239.  * @param ldc The LDAP connection being used.
  240.  * @param url The URL of the LDAP connection - used for deciding which cache to use.
  241.  * @param dn The DN of the object in which we do the compare.
  242.  * @param attrib The attribute within the object we are comparing for.
  243.  * @param value The value of the attribute we are trying to compare for. 
  244.  * @tip Use this function to determine whether an attribute/value pair exists within an
  245.  *      object. Typically this would be used to determine LDAP group membership.
  246.  * @deffunc int util_ldap_cache_compare(request_rec *r, util_ldap_connection_t *ldc,
  247.  *                                      const char *url, const char *dn, const char *attrib, const char *value)
  248.  */
  249. LDAP_DECLARE(int) util_ldap_cache_compare(request_rec *r, util_ldap_connection_t *ldc,
  250.                             const char *url, const char *dn, const char *attrib, const char *value);
  251.  
  252. /**
  253.  * Checks a username/password combination by binding to the LDAP server
  254.  * @param r The request record
  255.  * @param ldc The LDAP connection being used.
  256.  * @param url The URL of the LDAP connection - used for deciding which cache to use.
  257.  * @param basedn The Base DN to search for the user in.
  258.  * @param scope LDAP scope of the search.
  259.  * @param attrs LDAP attributes to return in search.
  260.  * @param filter The user to search for in the form of an LDAP filter. This filter must return
  261.  *               exactly one user for the check to be successful.
  262.  * @param bindpw The user password to bind as.
  263.  * @param binddn The DN of the user will be returned in this variable.
  264.  * @param retvals The values corresponding to the attributes requested in the attrs array.
  265.  * @tip The filter supplied will be searched for. If a single entry is returned, an attempt
  266.  *      is made to bind as that user. If this bind succeeds, the user is not validated.
  267.  * @deffunc int util_ldap_cache_checkuserid(request_rec *r, util_ldap_connection_t *ldc,
  268.  *                                          char *url, const char *basedn, int scope, char **attrs,
  269.  *                                          char *filter, char *bindpw, char **binddn, char ***retvals)
  270.  */
  271. LDAP_DECLARE(int) util_ldap_cache_checkuserid(request_rec *r, util_ldap_connection_t *ldc,
  272.                               const char *url, const char *basedn, int scope, char **attrs,
  273.                               const char *filter, const char *bindpw, const char **binddn, const char ***retvals);
  274.  
  275. /**
  276.  * Checks if SSL support is available in mod_ldap
  277.  * @deffunc int util_ldap_ssl_supported(request_rec *r)
  278.  */
  279. LDAP_DECLARE(int) util_ldap_ssl_supported(request_rec *r);
  280.  
  281. /* from apr_ldap_cache.c */
  282.  
  283. /**
  284.  * Init the LDAP cache
  285.  * @param pool The pool to use to initialise the cache
  286.  * @param reqsize The size of the shared memory segement to request. A size
  287.  *                of zero requests the max size possible from
  288.  *                apr_shmem_init()
  289.  * @deffunc void util_ldap_cache_init(apr_pool_t *p)
  290.  * @return The status code returned is the status code of the
  291.  *         apr_smmem_init() call. Regardless of the status, the cache
  292.  *         will be set up at least for in-process or in-thread operation.
  293.  */
  294. apr_status_t util_ldap_cache_init(apr_pool_t *pool, apr_size_t reqsize);
  295.  
  296. /**
  297.  * Display formatted stats for cache
  298.  * @param The pool to allocate the returned string from
  299.  * @tip This function returns a string allocated from the provided pool that describes
  300.  *      various stats about the cache.
  301.  * @deffunc char *util_ald_cache_display(apr_pool_t *pool)
  302.  */
  303. char *util_ald_cache_display(apr_pool_t *pool);
  304.  
  305.  
  306. /* from apr_ldap_cache_mgr.c */
  307.  
  308. /**
  309.  * Display formatted stats for cache
  310.  * @param The pool to allocate the returned string from
  311.  * @tip This function returns a string allocated from the provided pool that describes
  312.  *      various stats about the cache.
  313.  * @deffunc char *util_ald_cache_display(apr_pool_t *pool)
  314.  */
  315. char *util_ald_cache_display(apr_pool_t *pool);
  316.  
  317. #endif /* APU_HAS_LDAP */
  318. #endif /* UTIL_LDAP_H */
  319.